package org.ctstudio.oa.duty.dao;

import org.apache.ibatis.jdbc.SQL;
import org.ctstudio.oa.duty.bean.AbnormalSignApply;

public class AbnormalSignSql {
  public String add(AbnormalSignApply apply) {
    return new SQL() {
      {
        INSERT_INTO("duty.abnormalsignapply");
        VALUES("uid,applyTime,signType,abnormalDate,actualSignTime,status,reason,lastUpdateTime,approver,approveTime,suggestion",
            "#{uid},CURRENT_TIMESTAMP,#{signType},#{abnormalDate},#{actualSignTime},"
                + "#{status},#{reason},CURRENT_TIMESTAMP,#{approver},#{approveTime},#{suggestion}");
      }
    }.toString();
  }

  public String edit() {
    return new SQL() {
      {
        UPDATE("duty.abnormalsignapply");
        SET("signType=#{signType}");
        SET("applyTime=CURRENT_TIMESTAMP");
        SET("abnormalDate=#{abnormalDate}");
        SET("actualSignTime=#{actualSignTime}");
        SET("status=#{status}");
        SET("reason=#{reason}");
        WHERE("id=#{id}");
        AND();
        WHERE("status IN (0,3)");
      }
    }.toString();
  }

  public String approve() {
    return new SQL() {
      {
        UPDATE("duty.abnormalsignapply");
        SET("approver=#{approver}");
        SET("approveTime=CURRENT_TIMESTAMP");
        SET("suggestion=#{suggestion}");
        SET("status=#{status}");
        WHERE("id=#{id}");
      }
    }.toString();
  }
}
